package com.woniuxy.joylifeshop.service.serviceImpl;

import com.woniuxy.common.entity.ShopCommodityImage;
import com.woniuxy.common.mapper.ShopCommodityImageMapper;
import com.woniuxy.joylifeshop.service.PictureService;
import com.woniuxy.joylifeshop.util.AliyunOSSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Service
public class PitcherServiceImpl implements PictureService {

    @Autowired
    ShopCommodityImageMapper shopCommodityImageMapper;

    @Override
    public String addPictureService(MultipartFile img) {

        AliyunOSSUtil aliyunOSSUtil = new AliyunOSSUtil();
        String fileUri = null;
        try {
            fileUri = aliyunOSSUtil.uploadFile(img.getInputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }

        return fileUri;

    }

    @Override
    public void insertPicture(String src, String imgId) {


        try {
            ShopCommodityImage shopCommodityImage = shopCommodityImageMapper.selectByPrimaryKey(imgId);

            shopCommodityImage.setThumbnail(src);

            shopCommodityImageMapper.updateByPrimaryKey(shopCommodityImage);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
